package com.ruoyi.web.controller.project;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ProContract;
import com.ruoyi.project.service.IProContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * contractController
 *
 * @author ruoyi
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/project/contract")
public class ProContractController extends BaseController
{
    @Autowired
    private IProContractService proContractService;

    /**
     * 查询contract列表
     */
    @PreAuthorize("@ss.hasPermi('project:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProContract proContract)
    {
        startPage();
        List<ProContract> list = proContractService.selectProContractList(proContract);
        return getDataTable(list);
    }

    /**
     * 导出contract列表
     */
    @PreAuthorize("@ss.hasPermi('project:contract:export')")
    @Log(title = "contract", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProContract proContract)
    {
        List<ProContract> list = proContractService.selectProContractList(proContract);
        ExcelUtil<ProContract> util = new ExcelUtil<ProContract>(ProContract.class);
        util.exportExcel(response, list, "contract数据");
    }

    /**
     * 获取contract详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proContractService.selectProContractById(id));
    }

    /**
     * 新增contract
     */
    @PreAuthorize("@ss.hasPermi('project:contract:add')")
    @Log(title = "contract", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProContract proContract)
    {
        return toAjax(proContractService.insertProContract(proContract));
    }

    /**
     * 修改contract
     */
    @PreAuthorize("@ss.hasPermi('project:contract:edit')")
    @Log(title = "contract", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProContract proContract)
    {
        return toAjax(proContractService.updateProContract(proContract));
    }

    /**
     * 删除contract
     */
    @PreAuthorize("@ss.hasPermi('project:contract:remove')")
    @Log(title = "contract", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proContractService.deleteProContractByIds(ids));
    }
}
